package codeRandomThoughts.Test496下一个更大元素I;

import java.util.Arrays;
import java.util.Stack;

class Solution3 {
    public int[] nextGreaterElement(int[] nums1, int[] nums2) {
        //单调栈 栈内存的不是下标 是元素
        Stack<Integer> stack = new Stack<>();

        int[] result = new int[10001];
        Arrays.fill(result,-1);

        for (int i = 0; i < nums2.length; i++) {
            while (!stack.isEmpty() && nums2[i] > stack.peek()) {
                Integer pop = stack.pop();
                result[pop] = nums2[i];
            }

            stack.push(nums2[i]);
        }

        int[] ans = new int[nums1.length];

        for (int i = 0; i < ans.length; i++) {
            ans[i] = result[nums1[i]];
        }

        return ans;
    }
}
